#! /bin/bash

total_log_file="pthread_test.log"
main_log_file="mainpthread.log"

function extract_pthread_log_for
{
	# the easy method
	for i in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19
	do
		string="pthread$i"
		filename="$string.log"
		echo "$string , $filename"
		grep -i $string $total_log_file > $filename
	done
}

function extract_pthread_log_while
{
	i=0
	while [ $i -lt 20 ]
	do
		if [ $i -lt 10 ]; then
			var="pthread0$i"
		else
			var="pthread$i"
		fi
		filename="$var.log"
		echo "[$var, $filename]"
		grep -i $var $total_log_file > $filename
		i=$[$i+1]
	done
}

if [ -f $total_log_file ]
then
	grep -ni "mainpthread" $total_log_file > $main_log_file 
	extract_pthread_log_while 
fi

exit 0

